package controllerLayer;
import java.util.List;

import BDLayer.DBStore;
import BDLayer.IFDBStore;
import modelLayer.*;

public class StoreController {
	
	private ProductController prCtr = new ProductController();
	private PalletController paCtr = new PalletController();
	private IFDBStore storeDB = new DBStore();
	

	

	
	//interaction 4 find product
	
	//get all products
	public List<Product> getAllProduct(){
		return prCtr.getAllProduct();
	}	
	
	
	public Product findProductByID(String prID){
		return prCtr.getProductByID(prID);
	}
	
	
	//interaction 5 find pallets by product id
	public List<Pallet> getAllPalletByProductID(String productID){
		return paCtr.getAllPalletByProductID(productID);
	}
	
	//get All pallet
	public List<Pallet> getAllPallet(){
		return paCtr.getAllPallet();
	}
	
	//get pallet by ID
	public Pallet findPalletByID(int palletID){
		return paCtr.findPalletByID(palletID);
	}	
	

	//create and the insert Pallet see pallet Controller
	public boolean insertPallet(String batchNo, int noOfPlates, int supplierFail, int statusOnStore, String storeRef, String prID, int personID){
		return paCtr.createPallet(batchNo, noOfPlates, supplierFail, statusOnStore, storeRef, prID, personID);
	}
	
	
	
	
	//update pallet
	public boolean updatePallet(Pallet paObj){
		return paCtr.updatePallet(paObj);
	}
	
	
	public int deletePallet(int paID){
		return paCtr.deletePallet(paID);		
	}
	
	
	
	//getAll Stores
	public List<Store> getAllStore(){
		return storeDB.getAllStore(false);
	}
	
	
	public Store findStore(String ref, int i){
		List<Store> list_store = getAllStore();		
		
		if(list_store.size() < i){
			return null;
		}
		if(list_store.get(i).getReferenceNo().equals(ref)){
			
			return list_store.get(i);
		}
		else
		{
			return findStore(ref, i++);
		}	
		
	}
	
	
	//create and the insert Product see product Controller
	public boolean insertProduct(String productID, String colorCode, String storeRef, int personID){			
		return prCtr.insertProduct(productID, colorCode, new Store(storeRef), personID);		
	}	
	
	public int deleteProduct(String prID){
		return prCtr.deleteProduct(prID);
	}
	
	
	public void p(String e){System.out.println(e);}
}
